package com.example.iotlink.controller;

import com.example.iotlink.service.MqttGateway;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class MessageController {

    @Autowired
    MqttGateway mqttGateway;

    @RequestMapping(value="/sendMsg")
    public String sendMsg(@RequestParam String message){
        mqttGateway.sendToMqtt("defualt-topic:"+message);
        return "success";
    }


    @RequestMapping(value="/sendTopicMsg")
    public String sendTopicMsg(@RequestParam String message,@RequestParam String topic){
        mqttGateway.sendToMqtt(topic,"message:"+message);
        return "success";
    }


    @RequestMapping(value="/sendQosMsg")
    public String sendQosMsg(@RequestParam String message,@RequestParam String topic,@RequestParam Integer qos){
        mqttGateway.sendToMqtt(topic,qos,"message:"+message);
        return "success";
    }




}